package com.lc.guessTheWords.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;

import com.lc.guessTheWords.MainActivity;
import com.wiyun.engine.actions.ease.EaseAction;
import com.wiyun.engine.actions.ease.EaseBounceIn;
import com.wiyun.engine.nodes.Director;
import com.wiyun.engine.nodes.Scene;
import com.wiyun.engine.transitions.BottomSlideInTransition;
import com.wiyun.engine.transitions.ColorFadeTransition;
import com.wiyun.engine.transitions.FlipXTransition;
import com.wiyun.engine.transitions.TopSlideInTransition;
import com.wiyun.engine.types.WYColor3B;

public class GameUtil {

	public static void switchSceneFlipX(Scene toScene) {
		Scene scene = FlipXTransition.make(0.5f, toScene, false);
		Director.getInstance().replaceScene(scene);
	}

	public static void switchSceneNormal(Scene toScene) {
		Scene scene = ColorFadeTransition.make(1.5f, toScene, new WYColor3B(
				200, 200, 200));
		Director.getInstance().replaceScene(scene);
	}

	public static void switchSceneBottomSlide(Scene toScene) {
		BottomSlideInTransition trans = BottomSlideInTransition.make(1.2f,
				toScene);
		trans.autoRelease();
		EaseAction ease = EaseBounceIn.make();
		ease.autoRelease();
		trans.setInEaseAction(ease);
		Director.getInstance().replaceScene(trans);
	}

	public static void switchSceneTopSlide(Scene toScene) {
		TopSlideInTransition trans = TopSlideInTransition.make(1.2f, toScene);
		trans.autoRelease();
		EaseAction ease = EaseBounceIn.make();
		ease.autoRelease();
		trans.setInEaseAction(ease);
		Director.getInstance().replaceScene(trans);
	}

	/**
	 * 判断是否能够访问网络
	 * 
	 * @return
	 */
	public static boolean canAccessInternet() {
		NetworkInfo info = ((ConnectivityManager) MainActivity.instance
				.getSystemService(android.content.Context.CONNECTIVITY_SERVICE))
				.getActiveNetworkInfo();
		if (info == null || !info.isConnected()) {
			return false;
		}
		if (info.isRoaming()) {
			return false;
		}
		return true;
	}

	/**
	 * 返回当前程序版本名
	 */
	public static String getAppVersionName(Context context) {
		String versionName = "";
		try {
			// ---get the package info---
			PackageManager pm = context.getPackageManager();
			PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
			versionName = pi.versionName;
			if (versionName == null || versionName.length() <= 0) {
				return "";
			}
		} catch (Exception e) {
			Log.e("VersionInfo", "Exception", e);
		}
		return versionName;
	}

}
